var a1, a2;
var library;
var stage;

function main(_stage){
    var libraryLoader = new sp.Loader();

    console.log("-- main")

    var libraryURL = "assets/takara.swf";

    var libraryURLRequest = new sp.URLRequest(libraryURL);
    libraryLoader.load(libraryURLRequest);
    libraryLoader.contentLoaderInfo.addEventListener(sp.Event.COMPLETE, libraryLoaded);

    function libraryLoaded(event)
    {
        console.log("loaded");
        library = libraryLoader.contentLoaderInfo.applicationDomain;
        stage = _stage;
        animInit();
    }
}

var Anim1, Anim2;


function onObjectClicked() {
    console.log("clicked");
}

function mouseMove() {
    console.log("moved");
}

var char1, char2;

function addSprite(linkage) {
    TempClass = library.getDefinition(linkage);
    mc = new TempClass();
    stage.addChild(mc);
    return (mc);
}

function animInit() {
    console.log("animInit>>");

    // doesnt show in html version
    background = addSprite("music_city");
    background.x = 50;
    background.y = 200;
    background.scaleX = .5;
    background.scaleY = .5;

    // this doesnt show up at all in either version
    balloon = addSprite("balloon");
    balloon.x = 100;
    balloon.y = 250;

    char1 = addSprite("bones");
    char2 = addSprite("baghead");
    char1.x = 200;
    char1.y = 200;
    char2.x = 300;
    char2.y = 200;

//    gr1.addEventListener( sp.MouseEvent.MOUSE_DOWN, onObjectClicked );
//    stage.addEventListener( sp.MouseEvent.MOUSE_MOVE, mouseMove );
//    gr1.addEventListener( sp.TouchEvent.TOUCH_BEGIN, onObjectClicked );

    console.log("initDone");

}

function animLoop() {
    char1.x += 10;
    if (char1.x > 500) {
        char1.x = 0;
    }
    // setTimeout(animLoop, 500);
}





// Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT; 

// mc1 = new MovieClip(); 

/* 
 mc1.graphics.beginFill(0x336699); 
 mc1.graphics.drawRect(0,0,40,40); 
 // addChild(mySprite);   
 mySprite.addEventListener(TouchEvent.TOUCH_TAP, taphandler); 
 
 function taphandler(evt:TouchEvent): void { 
 myTextField.text = "I've been tapped"; 
 myTextField.y = 50; 
 addChild(myTextField); 
 }

 */

